package com.ncp.servlet.product;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.product.ManageFrontProductBiz;
import com.ncp.model.dao.DB;
import com.ncp.model.entity.product.ProductBasicBean;
import com.ncp.model.entity.product.ProductBasicLoadBean;
import com.ncp.model.entity.product.ProductSortBean;

public class ManagerShowBasicServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	   this.doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String type = request.getParameter("type");
	
		 int PageSize=10;
		 int PageNow=1;
		 
		 DB db = new DB();
		 db.setSql("select count(*) from PRODUCTBASIC");
		 int PageCount=db.getPageCount(PageSize);
		 ManageFrontProductBiz mbp = new ManageFrontProductBiz();
		 
		 if(type.equals("add")){
		    List<ProductSortBean> listparent =  mbp.getProductSort("select * from PRODUCTSORT where isover=0");
			request.setAttribute("listparent", listparent);
			request.getRequestDispatcher("pages/admin/product/ManagerBasicAdd.jsp").forward(request,response);
		 }
		 
		 if(type.equals("del")){
				String s_PageNow = request.getParameter("PageNow");
			 if(s_PageNow!=null){
					PageNow=Integer.parseInt(s_PageNow);
				}
			 String sql = "select ProductID,ProductImage,ProductName, EndTime," +
		 		"BeginTime, RetailPrice,MarketPrice,ProductType,ProductDiscount,CurrentPNumber," +
		 		"SoldPNumber from PRODUCTBASIC order by CurrentPNumber-SoldPNumber " +
		 		" limit "+(PageNow*PageSize-PageSize)+","+PageSize+"";
			 List<ProductBasicLoadBean> listbasic = mbp.getProductBasicBack(sql);
			 request.setAttribute("listbasic", listbasic);
			 request.setAttribute("PageCount", PageCount+"");
		     request.setAttribute("PageNow", PageNow+"");
		     request.getRequestDispatcher("pages/admin/product/ManagerBasicDelAndUp.jsp").forward(request,response);
		 }
		
	}

}
